<include file="__PUBLIC__/_header" />
<link href="__APP_SKIN__js/uploadify/uploadify.css?2" rel="stylesheet" type="text/css" />
<style>
    #b_pic1-button,#b_pic2-button{
        background:#428bca;
        color: #fff;
    }
</style>
<div class="navbar navbar-default" id="navbar">
    <script type="text/javascript">
        try{
            ace.settings.check('navbar' , 'fixed')}catch(e){

        }
    </script>
    <include file="__PUBLIC__/_header_title"/>
    <!-- /.container -->
</div>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <a class="menu-toggler" id="menu-toggler" href="#"> <span class="menu-text"></span> </a>
        <div class="sidebar" id="sidebar">
            <include file="__PUBLIC__/_nav" />
            <!-- /.nav-list -->
            <div class="sidebar-collapse" id="sidebar-collapse">
                <i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
            </div>
        </div>
        <div class="main-content">
            <div class="breadcrumbs" id="breadcrumbs">
                <script type="text/javascript">
                    try{
                        ace.settings.check('breadcrumbs' , 'fixed')
                    }catch(e){
                    }
                </script>
                <ul class="breadcrumb">
                    <li> <i class="icon-home home-icon"></i> <a href="#">首页</a> </li>
                    <li class="active">系统管理</li>
                    <li class="active">设置</li>
                </ul>
                <!-- .breadcrumb -->
            </div>
            <div class="page-content">
                <div class="page-header">
                    <h1> 系统管理 <small> <i class="icon-double-angle-right"></i> 基本资料 </small> </h1>
                </div>
                <!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="row">
                            <div class="col-xs-12">
                                <input type="hidden" name="m_id" id="m_id">
                                <form  method="post"><table id="data-table" class="table table-bordered table-hover definewidth m10" >
                                    <thead>
                                    <tr>
                                        <td colspan="13">供应商</td>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        <th width="10%">名称</th>
                                        <td>
                                            <input name="s_name" max-length="50" value="{$s_info.s_name}" type="text"/>
                                        </td>
                                    </tr><tr>
                                        <th width="10%">地址</th>
                                        <td>
                                            <input name="s_addr" max-length="50" value="{$s_info.s_addr}" type="text"/>
                                        </td>
                                    </tr><tr>
                                        <th width="10%">电话号码</th>
                                        <td>
                                            <input name="s_tel" max-length="50" value="{$s_info.s_tel}" type="text"/>
                                        </td>
                                    </tr><tr>
                                        <th width="10%">LOGO图标</th>
                                        <td>
                                            <img  id="s_logo" style="height:100px;"  src="{:Controller::getConfig('file_server_url')}/2013/{$s_info.s_image}"/><br>
                                            <a href="javascript:void(0)" id="b_pic1" idx="1" name="file_upload"  multiple="true" >上传LOGO图标</a>
                                            <input type="hidden" id="hidden_logo" value="{$s_info.s_image}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th width="10%">首页内容</th>
                                        <td>
                                            {$htmls.s_url}
                                         </td>
                                        <input type="hidden" id="hidden_url" value='{$s_info.s_url}'>
                                    </tr>
                                    <tr>
                                        <th width="10%">背景图</th>
                                        <td>

                                            <img id="s_bg_image" style="height:100px;"  src="{:Controller::getConfig('file_server_url')}/2013/{$s_info.s_bg_image}"/><br>
                                            <a id="b_pic2" idx="2" name="file_upload"   name="file_upload" multiple="true" >上传</a>
                                            <input type="hidden" id="hidden_bg" value="{$s_info.s_bg_image}">
                                        </td>
                                    </tr>

                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td colspan="13">
                                            <div class="col-md-offset-4 col-md-9">
                                                <button class="btn btn-info" type="button" id="base_submit"> <i class="icon-ok bigger-110"></i> 确定 </button>
                                                <button class="btn btn-info" type="button" id="base_cancel"> <i class="icon-ok bigger-110"></i> 存入草稿 </button>
                                            </div>
                                       </td>
                                    </tr>
                                    </tfoot>
                                </table>
                                </form>
                            </div>
                            <!-- /span -->
                        </div>
                        <!-- /row -->
                    </div>
                    <!-- PAGE CONTENT ENDS -->
                </div>
                <!-- /.row -->
            </div>
        </div>
    </div>
</div>
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="icon-double-angle-up icon-only bigger-110"></i>
</a>
<script src="__APP_SKIN__js/jquery-2.0.3.min.js"></script>
<script src="__APP_SKIN__js/bootstrap.min.js"></script>
<script src="__APP_SKIN__js/uploadify/jquery.uploadify.js?12" type="text/javascript"></script>
<script>
    $(function(){

        upload($("#b_pic1"));
        upload2($("#b_pic2"));
        $("#b_pic1-button .uploadify-button-text").html('上传LOGO');
        $("#b_pic2-button .uploadify-button-text").html('上传背景图');
        encodeURIComponent(editor_s_url.html($("#hidden_url").val()));
        $("#base_submit").click(function(){
            var s_name=$.trim($('input[name="s_name"]').val()),
                    s_addr=$.trim($('input[name="s_addr"]').val()),
                    s_tel=$.trim($('input[name="s_tel"]').val()),
                    s_logo=$.trim($('#hidden_logo').val()),
                    s_bg=$.trim($('#hidden_bg').val()),
                    s_url=encodeURIComponent(editor_s_url.html());

            if(s_name == ''){
                bootbox.dialog({
                    message: "<span class='btn-sm btn-danger'>名称不能为空！</span>"
                });
                return false;
            }
            if(s_addr == ''){
                bootbox.dialog({
                    message: "<span class='btn-sm btn-danger'>地址不能为空！</span>"
                });
                return false;
            }
            if (s_tel == '') {
                bootbox.dialog({
                    message: "<span class='btn-sm btn-danger'>电话不能为空！</span>"
                });
                return false;
            }
            if (s_logo == '') {
                bootbox.dialog({
                    message: "<span class='btn-sm btn-danger'>请上传logo！</span>"
                });
                return false;
            }
            if (s_url == '') {
                bootbox.dialog({
                    message: "<span class='btn-sm btn-danger'>请填写首页！</span>"
                });
                return false;
            }
            if (s_bg == '') {
                bootbox.dialog({
                    message: "<span class='btn-sm btn-danger'>请上传背景图！</span>"
                });
                return false;
            }
            var data={"s_name":s_name, "s_addr":s_addr, "s_tel":s_tel, "s_image":s_logo, "s_bg_image":s_bg,
                "s_url":s_url};
            $.ajax({
                type:"POST",
                async:false,
                dataType:"json",
                url:"{:Controller::createUrl('vis/profile/updateInfo')}",
                data:data,
                success:function(data,textStatus){
                    if(data.code==200){
                        bootbox.dialog({
                            message: "<span class='bigger-110'>"+data.msg+"</span>",
                            buttons:
                            {
                                "success" :
                                {
                                    "label" : "<i class='icon-ok'></i> Success!",
                                    "className" : "btn-sm btn-success",
                                    "callback": function() {
                                        window.location.reload();
                                    }
                                }
                            }
                        });
                    }else{
                        bootbox.dialog({
                            message: "<span class='btn-sm btn-danger'>"+data.msg+"</span>"
                        });
                    }
                },
                error:function(XMLHttpRequest,textStatus,errorThrown){
                    bootbox.dialog({
                        message: "<span class='btn-sm btn-danger'>网络错误！</span>"
                    });

                }
            });
        })


    })

    function upload(obj){
        $(obj).uploadify({
            'height'   : 40,
            'width'   : 140,
            'multi':true,
            'formData'      : {'file_type' : 0},
            'swf'      : '__APP_SKIN__js/uploadify/uploadify.swf',    //指定上传控件的主体文件
            'uploader' : '{:Controller::createUrl("vis/file/index")}',    //指定服务器端上传处理文件
            'fileTypeExts': '*.jpg',  //jpeg;*.gif;*.png
            'fileTypeDesc': 'Image Files',
            'fileSizeLimit' : '4096KB',
            'buttonText':"",
            'queueSizeLimit' : 5,
            //检测FLASH失败调用
            'onFallback':function(){
                alert("您的浏览器未安装FLASH控件，无法上传图片，请安装FLASH控件后再试！");
            },
            //返回一个错误，选择文件的时候触发
            'onSelectError':function(file, errorCode, errorMsg){
                switch(errorCode) {
                    case -100:
                        alert("上传的文件数量已经超出限制的"+$('a[name=file_upload]').uploadify('settings','queueSizeLimit')+"个文件！");
                        break;
                    case -110:
                        alert("文件 ["+file.name+"] 大小超出系统限制的"+$('a[name=file_upload]').uploadify('settings','fileSizeLimit')+"大小！");
                        break;
                    case -120:
                        alert("文件 ["+file.name+"] 大小异常！");
                        break;
                    case -130:
                        alert("文件 ["+file.name+"] 类型不正确！");
                        break;
                }
            },

            'onUploadError':function(file, errorCode, errorMsg, errorString){
                alert(errorString);
            },
            'onUploadSuccess' : function(file, data, response) {
                var service_url = "{:Controller::getConfig('file_server_url')}";
                var jsons       = "/2013/"+data;
                var file_logo=service_url+jsons;
                //$('#' + file.id).parent().find('img').remove();

                $('#' + file.id).parent().attr('filename',data);
                if ($(".no_pic").length > 0) {
                    $(".no_pic").remove();
                }
//                $("<div style='max-width:200px;height:40px;float: left;text-align: center'><input type='hidden' name='upload_files' value='"+data+"' />" +
//                        "<img class='preview-upload-pic' style='height:110px;max-width:160px; margin:5px;' src='"+service_url+jsons+"'/>&nbsp;" +data+"<br/><a href='javascript:void(0);' file_name='"+data+"' class='del_pic'>删除</a><br/><br/><br/></div>").insertBefore($('#' + file.id).parent());
//                bind_del_pic();
//if($(this).attr("inx"))

                $("#s_logo").attr("src",service_url+jsons );
                $("#hidden_logo").val(data);






            }
        });
    }
    function upload2(obj){
        $(obj).uploadify({
            'height'   : 40,
            'width'   : 140,
            'multi':true,
            'formData'      : {'file_type' : 0},
            'swf'      : '__APP_SKIN__js/uploadify/uploadify.swf',    //指定上传控件的主体文件
            'uploader' : '{:Controller::createUrl("vis/file/index")}',    //指定服务器端上传处理文件
            'fileTypeExts': '*.jpg',  //jpeg;*.gif;*.png
            'fileTypeDesc': 'Image Files',
            'fileSizeLimit' : '4096KB',
            'buttonText':"",
            'queueSizeLimit' : 5,
            //检测FLASH失败调用
            'onFallback':function(){
                alert("您的浏览器未安装FLASH控件，无法上传图片，请安装FLASH控件后再试！");
            },
            //返回一个错误，选择文件的时候触发
            'onSelectError':function(file, errorCode, errorMsg){
                switch(errorCode) {
                    case -100:
                        alert("上传的文件数量已经超出限制的"+$('a[name=file_upload]').uploadify('settings','queueSizeLimit')+"个文件！");
                        break;
                    case -110:
                        alert("文件 ["+file.name+"] 大小超出系统限制的"+$('a[name=file_upload]').uploadify('settings','fileSizeLimit')+"大小！");
                        break;
                    case -120:
                        alert("文件 ["+file.name+"] 大小异常！");
                        break;
                    case -130:
                        alert("文件 ["+file.name+"] 类型不正确！");
                        break;
                }
            },

            'onUploadError':function(file, errorCode, errorMsg, errorString){
                alert(errorString);
            },
            'onUploadSuccess' : function(file, data, response) {
                var service_url = "{:Controller::getConfig('file_server_url')}";
                var jsons       = "/2013/"+data;
                var file_logo=service_url+jsons;
                //$('#' + file.id).parent().find('img').remove();

                $('#' + file.id).parent().attr('filename',data);
                if ($(".no_pic").length > 0) {
                    $(".no_pic").remove();
                }
//                $("<div style='max-width:200px;height:40px;float: left;text-align: center'><input type='hidden' name='upload_files' value='"+data+"' />" +
//                        "<img class='preview-upload-pic' style='height:110px;max-width:160px; margin:5px;' src='"+service_url+jsons+"'/>&nbsp;" +data+"<br/><a href='javascript:void(0);' file_name='"+data+"' class='del_pic'>删除</a><br/><br/><br/></div>").insertBefore($('#' + file.id).parent());
//                bind_del_pic();
//if($(this).attr("inx"))

                $("#s_bg_image").attr("src",service_url+jsons );
                $("#hidden_bg").val(data);


            }
        });
    }
    function bind_del_pic(){
        $(".del_pic").click(function(){
            $(this).parent().remove();
            $("#del_attch").append("<input type='hidden' name='deled_pic[]' value='"+$(this).attr('file_name')+"' />");
        });
    }
</script>
</body>

</html>